package com.zxj.shop.admin.controller;


import com.zxj.shop.admin.entity.Permission;
import com.zxj.shop.admin.service.PermissionService;
import com.zxj.shop.admin.shiro.vo.PageVO;
import com.zxj.shop.admin.shiro.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "菜单管理")
@RestController
@RequestMapping("/api/admin/setting/menu")
public class MenuApiController {

    @Autowired
    PermissionService permissionService;

    @ApiOperation(value = "权限列表")
    @RequiresRoles(value = {"admin","guest","superadmin"},logical = Logical.OR)
    @GetMapping("/list")
    public PageVO<Permission> list() {
        List<Permission> list = permissionService.list();
        return PageVO.pageVO(list, (long) list.size());
    }

    @GetMapping("/tree")
    @ApiOperation(value = "获取所有目录菜单树接口")
    public ResultVO getAllMenusPermissionTree(@RequestParam(required = false) String permissionId) {
        return ResultVO.success(permissionService.selectAllMenuByTree(permissionId));
    }

}
